Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script to check connectivity to azure #2734

Merged
merged 1 commit into from
Dec 20, 2022

Conversation

giggsoff
Copy link
Contributor

Azure use signature checking across provided headers. It would be
nice to have a tool to debug unexpected intermediate headers
modifications that may lead to errors like "The MAC signature found in
the HTTP request is not the same as any computed signature". Even
without access_key the script allow to show headers server use to
calculate the signature.

Signed-off-by: Petr Fedchenkov giggsoff@gmail.com

@giggsoff giggsoff changed the title Add script to check connectivity to azure Script to check connectivity to azure Jul 28, 2022
@giggsoff giggsoff force-pushed the add-usefull-script branch 2 times, most recently from 4e02d1b to 5341977 Compare July 28, 2022 16:49
@giggsoff giggsoff marked this pull request as ready for review July 29, 2022 08:16
__EOT__
}

for prog in base64 openssl xxd curl
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be nice to wrap the code in main() function

done

# the same as in zedUpload
authorization="SharedKey"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason why some variables are in CAPS_LOCK, and other are not? Maybe keep all of them in lower case?

# Build the signature string

if [ -z "$LIMIT_IN_BYTES" ] || [ -z "$BLOB_NAME" ]; then
canonicalized_headers="${x_ms_date_h}\n${x_ms_version_h}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest to use braces everywhere for consistency


# in case of port provided we cannot use subdomain
# checked with azurite
if echo "$DOMAIN_NAME" | grep -q ":"; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's generally better to avoid starting sub process (grep). Something like this reads less obvious (thanks to /bin/sh instead of /bin/bash), but better from execution point of view:

case "${DOMAIN_NAME}" in
    *:*) echo "Found a colon";;
    *   ) echo "not found";;
esac


# Create the HMAC signature for the Authorization header
# shellcheck disable=SC2059
signature=$(printf "$string_to_sign" | openssl dgst -sha256 -mac HMAC -macopt "hexkey:$decoded_hex_key" -binary | base64)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be worth to check if openssl returned an error

Azure use signature checking across provided headers. It would be
nice to have a tool to debug unexpected intermediate headers
modifications that may lead to errors like "The MAC signature found in
the HTTP request is not the same as any computed signature". Even
without access_key the script allow to show headers server use to
calculate the signature.

Signed-off-by: Petr Fedchenkov <giggsoff@gmail.com>
@giggsoff giggsoff force-pushed the add-usefull-script branch from 5341977 to e4f8dee Compare August 1, 2022 08:36
@giggsoff
Copy link
Contributor Author

giggsoff commented Aug 1, 2022

@zededa-yuri thanks for recommendations, modified.

@rouming
Copy link
Contributor

rouming commented Dec 5, 2022

@giggsoff @eriknordmark Let's merge this?

Copy link
Contributor

@eriknordmark eriknordmark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's run the tests.

@eriknordmark eriknordmark merged commit 31c0508 into lf-edge:master Dec 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants